package com.globalwave.customer.web;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.globalwave.base.BaseAction;
import com.globalwave.common.ArrayPageList;
import com.globalwave.customer.entity.CustomerProfile;
import com.globalwave.customer.entity.CustomerProfileSO;
import com.globalwave.customer.service.CustomerProfileBO;
import com.globalwave.system.web.annotations.Pid;
import com.opensymphony.xwork2.Preparable;


@Service("customer_customerProfileAction")
@Scope("prototype")
public class CustomerProfileAction extends BaseAction implements Preparable {

    private static final long serialVersionUID = 8582051849254108462L;

    private CustomerProfileBO customerProfileBO ;
    private CustomerProfile customerProfile ;
    private CustomerProfileSO criterion ; 
    private Long cid ;

    @Pid(value=1001)
    public String get()  throws Exception {              
        
        Object customerProfile = customerProfileBO.get(cid) ;

        renderXML(this.getMessage(customerProfile, "").asXML()) ;
        
        return null;    
        
    }


    @Pid(value=1001)
    public String list() throws Exception {      
        
    	if (pageIndex == 0) {
    		pageIndex = 1;
    	}
    	
        ArrayPageList<CustomerProfile> pageList = 
            customerProfileBO.query(criterion,pageIndex,pageSize,null) ;

        renderXML(pageList.asXML()) ;
        
        return null ;    
        
    }

    @Pid(value=1002)
    public String create()  throws Exception {              
        
        Object newProfile = customerProfileBO.create(customerProfile) ;

        renderXML(this.getSuccessCreateMessage(newProfile).asXML()) ;
        
        return null;    
        
    }

    @Pid(value=1003)
    public String update()  throws Exception {     
        
    	customerProfileBO.update(customerProfile) ;

        renderXML(this.getSuccessUpdateMessage(customerProfile).asXML()) ;
        
        return null;    
        
    }

    @Pid(value=1004)
    public String delete()  throws Exception {
        if (ids == null) { 
        	customerProfileBO.delete(customerProfile) ;
        } else {
        	customerProfileBO.deleteAll(ids) ;
        }

        renderXML(this.getSuccessDeleteMessage().asXML()) ;
        
        return null;    
        
    }
    
    
	public CustomerProfileBO getCustomerProfileBO() {
		return customerProfileBO;
	}

	public void setCustomerProfileBO(CustomerProfileBO customerProfileBO) {
		this.customerProfileBO = customerProfileBO;
	}


	public CustomerProfile getCustomerProfile() {
		return customerProfile;
	}


	public void setCustomerProfile(CustomerProfile customerProfile) {
		this.customerProfile = customerProfile;
	}


	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		
	}


	public Long getCid() {
		return cid;
	}


	public void setCid(Long cid) {
		this.cid = cid;
	}


	public CustomerProfileSO getCriterion() {
		return criterion;
	}


	public void setCriterion(CustomerProfileSO criterion) {
		this.criterion = criterion;
	}
    
    
}
